package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.PointMsg;
import cn.wolfcode.trip.base.query.PointMsgQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IPointMsgService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/msgs")
public class PointMsgController {
    @Autowired
    private IPointMsgService service;

    /**
     * 查询某个用户的未读消息数量
     * @param userId 用户id
     * @return
     */
    @GetMapping("/{userId}")
    public Object getUnread(@PathVariable Long userId){
        Integer num = service.getUnread(userId);
        return num;
    }

    /**
     * 根据用户ID分页查询用户的系统消息列表
     * @param userId 用户ID
     * @return
     */
    @GetMapping("/list")
    public Object selectMsgList(PointMsgQueryObject qo){
        qo.setOrderBy("p.createTime desc");
        qo.setPageSize(10);
        PageInfo<PointMsg> result = service.selectForList(qo);
        return result;
    }

    @PutMapping("/{userId}")
    public void changeRead(@PathVariable Long userId){
        service.changeRead(userId);

    }

}
